<ui:composition template="/pages/faces/ui/layout/ces_template.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:composite="http://java.sun.com/jsf/composite">

	<ui:define name="pageTitle">
		<h:outputText value="#{msg.courses_title}" />
	</ui:define>

	<ui:define name="pageBody">
		<h:form>
			<h:panelGrid columns="2">

				<h:outputText value="#{msg.course_name}" />
				<h:outputText value="#{courseBean.course.courseName}"
					rendered="#{sessionBean.userAdmin == false}" />
				<p:inputText value="#{courseBean.course.courseName}"
					rendered="#{sessionBean.userAdmin}" />

				<h:outputText value="#{msg.year}" />
				<h:outputText value="#{courseBean.course.year}"
					rendered="#{sessionBean.userAdmin == false}" />
				<p:inputText value="#{courseBean.course.year}"
					rendered="#{sessionBean.userAdmin}" />

				<h:outputText value="#{msg.semester}" />
				<h:outputText value="#{courseBean.course.semester.semesterName}"
					rendered="#{sessionBean.userAdmin == false}" />
				<p:selectOneButton value="#{courseBean.selectedSemesterId}"
					rendered="#{sessionBean.userAdmin}">
					<f:selectItems value="#{courseBean.semesterList}" var="semester"
						itemValue="#{semester.semesterId}"
						itemLabel="#{semester.semesterName}">
					</f:selectItems>
				</p:selectOneButton>

				<h:outputText value="#{msg.workload}" />
				<h:outputText value="#{courseBean.course.workload}"
					rendered="#{sessionBean.userAdmin == false}" />
				<p:inputText value="#{courseBean.course.workload}"
					rendered="#{sessionBean.userAdmin}" />

				<h:outputText value="#{msg.specialty}" />
				<h:dataTable value="#{courseBean.course.specialties}"
					var="specialty" rendered="#{sessionBean.userAdmin == false}">
					<h:column>
						<h:outputText value="#{specialty.specialtyName}"></h:outputText>
					</h:column>
				</h:dataTable>
				<p:selectManyButton value="#{courseBean.selectedSpecialties}"
					rendered="#{sessionBean.userAdmin}">
					<f:selectItems value="#{courseBean.specialtyList}" var="specialty"
						itemValue="#{specialty.specialtyId}"
						itemLabel="#{specialty.specialtyName}">
					</f:selectItems>
				</p:selectManyButton>

				<h:outputText value="#{msg.courses}" />
				<h:dataTable value="#{courseBean.course.grades}" var="grade"
					rendered="#{sessionBean.userAdmin == false}">
					<h:column>
						<h:outputText value="#{grade.gradeNumber}" />
					</h:column>
				</h:dataTable>
				<p:selectManyButton value="#{courseBean.selectedGrades}"
					rendered="#{sessionBean.userAdmin}">
					<!-- the item labes starts with SPACE because of String cast exception -->
					<f:selectItems value="#{courseBean.gradeList}" var="grade"
						itemValue="#{grade.gradeId}" itemLabel=" #{grade.gradeNumber}">
					</f:selectItems>
				</p:selectManyButton>

				<h:outputText value="#{msg.lecturer_name}" />
				<h:outputText value="#{courseBean.course.lecturer.lecturerName}"
					rendered="#{sessionBean.userAdmin == false}" />
				<p:selectOneMenu value="#{courseBean.selectedLecturerId}"
					rendered="#{sessionBean.userAdmin}">
					<f:selectItems value="#{courseBean.lecturerList}" var="lecturer"
						itemValue="#{lecturer.lecturerId}"
						itemLabel=" #{lecturer.lecturerName}">
					</f:selectItems>
				</p:selectOneMenu>

				<h:outputText value="#{msg.course_annotation}" />
				<p:editor value="#{courseBean.course.courseAnnotation}" width="600"
					disabled="true" rendered="#{sessionBean.userAdmin == false}" />
				<p:editor value="#{courseBean.course.courseAnnotation}" width="600"
					rendered="#{sessionBean.userAdmin}" />

				<h:outputText value="#{msg.preliminary_requirements}" />
				<p:editor value="#{courseBean.course.preliminaryRequirements}"
					width="600" disabled="true"
					rendered="#{sessionBean.userAdmin == false}" />
				<p:editor value="#{courseBean.course.preliminaryRequirements}"
					width="600" rendered="#{sessionBean.userAdmin}" />

				<h:outputText value="#{msg.examination_form}" />
				<p:editor value="#{courseBean.course.examinationForm}" width="600"
					disabled="true" rendered="#{sessionBean.userAdmin == false}" />
				<p:editor value="#{courseBean.course.examinationForm}" width="600"
					rendered="#{sessionBean.userAdmin}" />

				<h:outputText value="#{msg.summary}" />
				<p:editor value="#{courseBean.course.summary}" width="600"
					disabled="true" rendered="#{sessionBean.userAdmin == false}" />
				<p:editor value="#{courseBean.course.summary}" width="600"
					rendered="#{sessionBean.userAdmin}" />

				<h:outputText value="#{msg.literature}" />
				<p:editor value="#{courseBean.course.literature}" width="600"
					disabled="true" rendered="#{sessionBean.userAdmin == false}" />
				<p:editor value="#{courseBean.course.literature}" width="600"
					rendered="#{sessionBean.userAdmin}" />

				<h:outputText value="#{msg.course_user_rating}" />
				<p:rating value="#{courseBean.userRating}" stars="6"
					disabled="#{sessionBean.userAdmin}" />
					
				<h:outputText value="#{msg.course_rating}" />
				<p:rating value="#{courseBean.rating}" stars="6"
					disabled="true" />
					
				<h:outputText value="#{msg.course_rating}" />
				<h:outputText value="#{courseBean.rating}" >
					<f:convertNumber maxFractionDigits="2" />
				</h:outputText>							

				<h:outputText value="#{msg.course_ratingCounter}" />
				<h:outputText value="#{courseBean.ratingCounter}" />

			</h:panelGrid>

			<p:commandButton value="#{msg.submit}"
				actionListener="#{courseBean.saveCourse}"
				rendered="#{sessionBean.userAdmin}" />

			<p:commandButton value="#{msg.assessCourse}"
				action="#{courseBean.assessCourse}"
				rendered="#{sessionBean.userStudent}" />

		</h:form>
	</ui:define>

</ui:composition>